package com.gupao.pattern.proxy.dynamicproxy.jdk.custom;

import com.gupao.pattern.proxy.Person;
import com.gupao.pattern.proxy.dynamicproxy.jdk.Girl;

import java.lang.reflect.Method;

public class MeiPo implements GPInvocationHandler {

    private Object targate;


    public Object getInstance(Object targate) {
        this.targate = targate;
        Class<?> clazz = targate.getClass();

        return GPProxy.newProxyInstance(new GPClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆：我要给你找对象，现在已经拿到你的需求");

        System.out.println("开始物色");
        Object obj = method.invoke(this.targate, args);
        System.out.println("如果合适的话，准备办事");
        return obj;
    }

    public static void main(String[] args) {
        Person person= (Person) new MeiPo().getInstance(new Girl());
        System.out.println(person.findLove("张三", 18));
    }
}
